#pragma once
#include<iostream>
#include<string>
#include<fstream>
const std::string blankline = "\r\n"; 
class Uitl
{
public:
    static bool ReadReqOneStr(std::string &reqstr,std::string* out)
    {
        //找\r\n
        auto pos = reqstr.find(blankline);
        if(pos==std::string::npos)
        {
            //没找到，说明报文不完整
            return false;
        }
        *out= reqstr.substr(0,pos);
        //获取完将获取的信息从原报文中删除
        reqstr.erase(0,pos+blankline.size());
        return true;
    }

    static bool ReadFileText(std::string& filename,std::string* text)
    {
        int filesize = FileSize(filename);
        if(filesize > 0)
        {
            std::ifstream in(filename);
            if(!in.is_open())
                return false;
            text->resize(filesize);
            in.read((char*)(text->c_str()), filesize);
            in.close();
        }
        else
        {
            return false;
        }

        return true;
    }
    static int FileSize(const std::string &filename)
    {
        std::ifstream in(filename, std::ios::binary);
        if(!in.is_open())
            return -1;
        in.seekg(0, in.end);
        int filesize = in.tellg();
        in.seekg(0, in.beg);
        in.close();
        return filesize;
    }
};